﻿#define CONN
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Configuration;
using Teradata.Client.Provider;
using System.IO;

public partial class Title2 : System.Web.UI.Page
{

    bool bWorkingDisconnected = Convert.ToBoolean(ConfigurationManager.AppSettings["WorkingDisconnected"]);

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.Controls.AddAt(0, new System.Web.UI.HtmlControls.HtmlMeta { HttpEquiv = "X-UA-Compatible", Content = "IE=EmulateIE7" });
        if ((Boolean)HttpContext.Current.Application["Cache Is Stale"] == true)
        {
            imgCaching.Attributes["src"] = imgCaching.Attributes["src"].Replace("blue", "red");
            imgCaching.Attributes["title"] = "Rebuilding Cache from Teradata";
            imgCaching.Visible = true; 
        }
        else
            if ((Boolean)HttpContext.Current.Application["Reload Cache"] == true)
            {
                imgCaching.Attributes["src"] = imgCaching.Attributes["src"].Replace("blue", "yellow");
                imgCaching.Attributes["title"] = "Rebuilding Cache from Local Storage";
                imgCaching.Visible = true;
            }
        Session["Connected"] = false;
        DateTime dtSales = Convert.ToDateTime(System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("SQL\\Data\\ServerSalesDate.txt")));
        Session["SalesDate"] = dtSales;
        litSalesDate.Text = string.Format("\xa0Service Orders as of <b>{0}</b>", dtSales.ToLongDateString());
        DateTime startTime = DateTime.Now; Trace.Write(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Started");
        Session["PropertiesDate"] = Application["PropertiesDate"];
        //Literal1.Text = (new Properties("")).PropertiesDate + " Property List";

        DateTime stopTime = DateTime.Now; TimeSpan duration = stopTime - startTime; Trace.Write(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Ended: " + duration.ToString());
    }

    //protected void Timer1_Tick(object sender, EventArgs e)
    //{

    //    int nSeconds = TeradataSpeed();
    //    string imgColor = string.Empty;

    //    if (nSeconds < 2) imgColor = "blue";
    //    else if (nSeconds < 3) imgColor = "yellow";
    //    else imgColor = "red";

    //    imgCaching.Attributes["src"] = string.Format("images/led-{0}.gif", imgColor);
    //    imgCaching.Attributes["title"] = nSeconds.ToString();
    //    imgCaching.Visible = nSeconds > 0;

    //}

    //protected int TeradataSpeed()
    //{
    //    DateTime startTime = DateTime.Now;

    //    if ((bool)Session["Connected"])
    //    {
    //        System.Data.DataSet tmpDataSet = new System.Data.DataSet();
    //        String SQL =
    //                     "SELECT AREA_MGR, AREA_MGR \"ACCT_MGR\", 1 LVL, 1 ORD FROM SUNRISE_TEST.ACC_BASE_DATA GROUP BY AREA_MGR " +
    //                     "UNION SELECT 'Southeast','Steve Shaw',  0 LVL, 0 ORD FROM SUNRISE_TEST.ACC_BASE_DATA " +
    //                     "UNION SELECT AREA_MGR, ACCT_MGR, 2 LVL, 1 ORD FROM SUNRISE_TEST.ACC_BASE_DATA ORDER BY 4,1,3,2;" +
    //                     "SELECT PORTFOLIO TXT, PORTFOLIO VAL FROM SUNRISE_TEST.ACC_BASE_DATA GROUP BY 1 ORDER BY 1;" +
    //                     "SELECT CASE MARKET WHEN 'ALM' THEN 'ALABAMA-LOUISIANA-MISSISSIPPI' WHEN 'FL' THEN 'FLORIDA' WHEN 'GA' THEN 'GEORGIA' WHEN 'KTNS' THEN 'KENTUCKY-TENNESSEE-CAROLINAS' END TXT, MARKET VAL FROM SUNRISE_TEST.ACC_BASE_DATA GROUP BY 1,2 ORDER BY 1;";

    //        using (TdConnection cn = new TdConnection(ConfigurationManager.ConnectionStrings["TDConnString"].ConnectionString))
    //        {
    //            try
    //            {
    //                cn.Open();
    //                using (TdDataAdapter da = new TdDataAdapter(SQL, cn))
    //                {
    //                    da.SelectCommand.CommandTimeout = 0;
    //                    da.Fill(tmpDataSet);
    //                }
    //            }
    //            catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }
    //        }
    //        DateTime stopTime = DateTime.Now;
    //        TimeSpan duration = stopTime - startTime;

    //        return (int)duration.TotalSeconds;
    //    }
    //    else { return 0; }

    //}

    //protected void Timer1_Tick(object sender, EventArgs e)
    //{
   
    //    TimeSpan duration = DateTime.Now - Caching.Started;
    //    string sText = Caching.CachingText;
    //    if (sText == "Finis")
    //    {
    //        Timer1.Enabled = false;
    //        Literal1.Text = duration.ToString().Substring(0, 8);
    //    }
    //    else
    //    {
    //        Literal1.Text = duration.ToString().Substring(0,8) + " " + sText;
    //    }
    //}

}